package com.wnxy.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class DBUtil {


    private static SqlSessionFactory sqlSessionFactory;


    static{
        SqlSessionFactoryBuilder  sqlSessionFactoryBuilder=new SqlSessionFactoryBuilder();


        try {
            InputStream in=Resources.getResourceAsStream("mybatis-config.xml");


            sqlSessionFactory=sqlSessionFactoryBuilder.build(in);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    public static SqlSession openSession(boolean flag){

        return sqlSessionFactory.openSession(flag);
    }


    public static SqlSession openSession(){
        return openSession(false);
    }
}
